package com.example.springboot.controller;

import com.example.springboot.common.Result;
import com.example.springboot.entity.Role;
import com.example.springboot.service.RoleService;
import com.github.pagehelper.PageInfo;
import com.github.pagehelper.page.PageMethod;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author linyue
 * @since 2024-04-25
 */
@RestController
@RequestMapping("/role")
@Api(value = "角色基础", tags = "角色基础数据")
public class RoleController {
    @Resource
    private RoleService roleService;

    @PostMapping("/add")
    @ApiOperation(value = "添加角色")
    public Result add(@RequestBody Role role) {
        roleService.save(role);
        return Result.success();
    }

    @DeleteMapping("/delete")
    @ApiOperation(value = "删除角色", notes = "根据id删除角色")
    public Result deleteById(@PathVariable Integer id) {
        roleService.removeById(id);
        return Result.success();
    }

    @PostMapping("/update")
    @ApiOperation(value = "修改角色", notes = "修改角色")
    public Result updateById(@RequestBody Role role) {
        roleService.updateById(role);
        return Result.success();
    }

    @GetMapping("/selectAll")
    @ApiOperation(value = "查询所有任务", notes = "查询所有任务")
    public Result selectAll(@RequestParam Integer pageNum,
                            @RequestParam Integer pageSize) {
        PageMethod.startPage(pageNum, pageSize);
        List<Role> list = roleService.list();
        PageInfo<Role> roleList = new PageInfo<>(list);
        return Result.success(roleList);
    }


}
